<?php
class featured_media_model extends CI_Model {
	public function __construct() {
		parent::__construct ();
		$this->db = $this->load->database ( 'default', true );
	}
	public function query_featured_media_list($media_type) {
		$media_type = $this->db->escape_str ( $media_type );
		$sql = "select website_featured_media.*,location 
				from website_featured_media inner join media 
				on media.media_id = website_featured_media.media_id
			where website_featured_media.media_type ='$media_type'
			order by sort_num desc
		";
		$query = $this->db->query ( $sql );
		if ($query->num_rows ()) {
			return $query->result_array ();
		}
	}
	public function query_sort_num() {
		$sql = "select max(sort_num) as max_sort_num from website_featured_media";
		$query = $this->db->query ( $sql );
		if ($query->num_rows ()) {
			$row = $query->row_array ();
			return $row ['max_sort_num'];
		}
	}
	public function insert_featured_media($featured_media) {
		$this->db->insert ( "website_featured_media", $featured_media );
	}
	public function query_featured_media_info($featured_id) {
		$featured_id = $this->db->escape_str ( $featured_id );
		$sql = "select * from  website_featured_media where featured_id ='$featured_id' limit 1 ";
		$query = $this->db->query ( $sql );
		if ($query->num_rows ()) {
			return $query->row_array ();
		}
	}
	public function update_featured_media($featured_media, $featured_id) {
		$this->db->where ( "featured_id", $featured_id );
		$this->db->update ( "website_featured_media", $featured_media );
	}
	
	public function delete_featured_media ( $featured_id ){
		$sql = "delete from  website_featured_media where featured_id ='$featured_id' limit 1 ";
		$query = $this->db->query ( $sql );
	}
}

